package com.foogui.mq.consumer;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RocketMQMessageListener(topic = "order-topic", consumerGroup = "order_consume_group")
public class OrderMsgConsumer implements RocketMQListener<String> {

    @Override
    public void onMessage(String msg) {
        

        // 转json拿到数据
        JSONObject jsonObject = JSONUtil.parseObj(msg);
        //传的时候传什么类型，就用什么类型取
        String userId = jsonObject.getStr("userId");
        String commodityCode = jsonObject.getStr("commodityCode");
        Integer count = jsonObject.getInt("count");

        log.info("收到order-topic消息：userId={}, commodityCode={}, count={}", userId, commodityCode, count);

    }
}
